﻿Public Class ClassHisto
    Private Const Max As Integer = 6
    Public Liste() As ClassArchive
    Public Cle As String

    Public Sub New()
        Cle = ""
        ReDim Liste(0)
    End Sub

    Public Sub Vider()
        For i = 0 To Count()
            Liste(i) = Nothing
        Next
        ReDim Liste(0)
    End Sub

    Public Function Count() As Integer
        Return Liste.GetUpperBound(0)
    End Function

    Public Function GetNextDate()
        If Me.Count > 0 Then
            Return Liste(Count()).DateFichier
        Else
            Return ""
        End If
    End Function

    Public Function Pop() As ClassArchive
        If Count() > 0 Then
            Dim oArc As ClassArchive = Liste(Count())
            ReDim Preserve Liste(Count() - 1)
            Return oArc
        Else
            Return Nothing
        End If
    End Function

    Public Sub Push(ByVal oArc As ClassArchive)
        If Count() = Max Then
            'On décale la pile et on perd le plus ancien élément
            For i = 1 To Count() - 1
                Liste(i) = Liste(i + 1)
            Next
        Else
            'On ajoute un élément à la pile
            ReDim Preserve Liste(Count() + 1)
        End If
        Liste(Count()) = oArc
    End Sub
End Class
